package com.studio5704website.infrastructure.service;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.RequestHandlerSelectors.withMethodAnnotation;

/**
 * @author 高威
 * Swagger2配置
 */
@Configuration
@EnableSwagger2
@ComponentScan(basePackages = "com.studio5704website.api")
public class Swagger2Config {
    @Bean
    public Docket swaggerSpringMvcPlugin(){
        //指定规范，这里是SWAGGER_2
        return new Docket(DocumentationType.SWAGGER_2)
                //设定Api文档头信息，这个信息会展示在文档UI的头部位置
                .apiInfo(swaggerDemoApiInfo())
                .select()
                .build();
    }

    /**
     * 自定义API文档基本信息实体
     * @return
     */
    private ApiInfo swaggerDemoApiInfo(){
        //构建联系实体，在UI界面会显示
        Contact contact = new Contact("5704", "2592006268@qq.com", "2592006268@qq.com");
        return new ApiInfoBuilder()
                .contact(contact)
                //文档标题
                .title("5704 website RESTFUL 文档")
                //文档描述
                .description("工作室网站后台API文档")
                //文档版本
                .version("1.0.0")
                .build();
    }

}
